#include "{{ var_filename }}.h"
#include <string.h>

typedef struct TAtServerExtIcfgTag TAtServerExtIcfg; 
struct TAtServerExtIcfgTag
{
{%- for var_param in var_param_list %}
    {%- if '_icfg_' in  ('_'+(var_param['属性名'] | replace('.', '_') | replace('/', '_'))) %}
        {%- if var_param.get('数据类型', 'Unknown') == 'str' %}
    char {{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }}[128];
        {%- elif var_param.get('数据类型', 'Unknown') == 'int' %}
    int {{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }};
        {%- endif %}  
    {%- endif %}
{%- endfor %}
};

static TAtServerExtIcfg g_at_server_ext_icfg_attr_ = {0};

void AtServerExtIcfgInit(void)
{
    // 初始化属性
    memset(&g_at_server_ext_icfg_attr_, 0, sizeof(g_at_server_ext_icfg_attr_));
}




{%- for var_param in var_param_list %}
{%- if '_icfg_' in  ('_'+(var_param['属性名'] | replace('.', '_') | replace('/', '_'))) %}
/**
 * 属性名: {{ var_param.get('属性名', 'Unknown') }}
 * 数据类型: {{ var_param.get('数据类型', 'Unknown') }}
 * 读写: {{ var_param.get('读写', 'Unknown') }}
 * 属性说明: {{ var_param.get('属性说明', 'Unknown') }}
 */
    {%- if 'R' in var_param.get('读写', 'Unknown') %}
        {%- if var_param.get('数据类型', 'Unknown') == 'str' %}
char* RteAtServerExtGetStr_{{ var_param['属性名'] | replace('.', '_') | replace('/', '_') }}(int AChipNo, int AExtID, int* ARetCode)
{
    char *result = g_at_server_ext_icfg_attr_.{{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }};
    
    if (ARetCode != NULL)
    {
        *ARetCode = strlen(result);
    }

    return result;
}
        {%- elif var_param.get('数据类型', 'Unknown') == 'int' %}
int RteAtServerExtGetInt_{{ var_param['属性名'] | replace('.', '_') | replace('/', '_') }}(int AChipNo, int AExtID, int* ARetCode)
{
    int result = g_at_server_ext_icfg_attr_.{{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }};
    
    if (ARetCode != NULL)
    {
        *ARetCode = ATS_rSuccess;
    }
    return result;
}
        {%- endif %}    
    {%- endif %}

    {%- if 'W' in var_param.get('读写', 'Unknown') %}
        {%- if var_param.get('数据类型', 'Unknown') == 'str' %}
int RteAtServerExtSetStr_{{ var_param['属性名'] | replace('.', '_') | replace('/', '_') }}(int AChipNo, int AExtID, const char* AValue, int ASize)
{
    int result = ATS_rSuccess;
    
    if (AValue == NULL)
    {
        result = ATS_rIsIllegal;
    }
    else if (ASize >= sizeof(g_at_server_ext_icfg_attr_.{{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }}))
    {
        result = ATS_rSizeError;
    }
    else
    {
        strncpy(g_at_server_ext_icfg_attr_.{{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }}, AValue, ASize);
        g_at_server_ext_icfg_attr_.{{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }}[ASize] = '\0';
    }

    return result;
}
        {%- elif var_param.get('数据类型', 'Unknown') == 'int' %}
int RteAtServerExtSetInt_{{ var_param['属性名'] | replace('.', '_') | replace('/', '_') }}(int AChipNo, int AExtID, int AValue)
{
    int result = ATS_rSuccess;
    g_at_server_ext_icfg_attr_.{{ var_param['属性名'][5:] | replace('.', '_') | replace('/', '_') }} = AValue;
    return result;
}
        {%- endif %}
    {%- endif %}
{%- endif %}
{%- endfor %}


